/*
 * Filename: /home/long/work/sample/c/2021-f0803/nn_mod.c
 * Path: /home/long/work/sample/c/2021-f0803
 * Created Date: Saturday, April 17th 2021, 2:26:04 pm
 * Author: long
 * 写程序，输入一个数n(n>=100)，请输出`n! mod 100007`的结果。
 * Copyright (c) 2021 Your Company
 */

int n_mod_result(int n, int mod_n)
{
    // 分析 n! mod mod_n = ((n-1)! mod mod_n)*n, 则可递归展开到1! mod n
    if (n==1) return n % mod_n;
    return (n_mod_result(n-1, mod_n) * n) % mod_n;
}


void main()
{
    // int mod_n = 100007;
    int mod_n = 100007 * 2;
    for(int i=1; i<100; i++) {
        printf("%d! mod %d = %d\n", i, mod_n, n_mod_result(i, mod_n));
    }
}